from common.unit import AndroidUI
import time


#    #com.bluephone/com.bluecart.activity.SplashActivity

class AndroidTest:
    def __init__(self):
        self.driver = AndroidUI()


    def test_login(self):
        self.driver.find_element_by_text('我的').click()
        self.driver.find_element_by_id('com.sofmit.gzsk:id/my_head').click()
        self.driver.find_element_by_id("com.sofmit.gzsk:id/editText1").send_keys(17706852578)
        self.driver.find_element_by_id("com.sofmit.gzsk:id/editText2").send_keys(83190042)
        # self.driver.find_element_by_xpath('//*[@resource-id="com.sofmit.gzsk:id/editText1"]').send_keys(17706852578)
        # self.driver.find_element_by_xpath('//*[@resource-id="com.sofmit.gzsk:id/editText2"]').send_keys(83190042)
        self.driver.find_element_by_text('登 录').click()
        if self.driver.find_element_by_id('com.sofmit.gzsk:id/my_head'):
            print("测试登录成功")
            self.driver.write_result("登录测试", "成功")
        else:
            print("测试登录失败")
            self.driver.write_result("登录测试", "失败")
            self.driver.stop()
            self.driver.start_app('com.sofmit.gzsk', '.mvp.ui.splash.SplashActivity')
    #测试服务的一键报警
    def test_service_alarm(self):
        self.driver.find_element_by_text('首页').click()
        self.driver.find_element_by_text('服务').click()
        if self.driver.find_element_by_text('一键报警'):
            self.driver.find_element_by_text('一键报警').click()
            if self.driver.find_element_by_id('com.sofmit.gzsk:id/cricleimage1'):
                print("一键报警测试成功")
                self.driver.write_result("一键报警测试","成功")
                self.driver.find_element_by_id("com.sofmit.gzsk:id/toolbar_back").click()
                self.driver.find_element_by_id("com.sofmit.gzsk:id/toolbar_back").click()

            else:
                print("一键报警测试失败")
                self.driver.write_result("一键报警测试", "失败")
                self.driver.stop()
                self.driver.start_app('com.sofmit.gzsk', '.mvp.ui.splash.SplashActivity')
        else:
            print("无法进入服务界面")
            self.driver.write_result("进入服务界面", "失败")
            self.driver.stop()
            self.driver.start_app('com.sofmit.gzsk', '.mvp.ui.splash.SplashActivity')


    #测试商城
    def test_store(self):
        self.driver.find_element_by_text('首页').click()
        self.driver.find_element_by_text('商城').click()
        time.sleep(5)
        # if self.driver.find_element_by_id('com.sofmit.gzsk:id/in_rb_1'):  #电脑
        if self.driver.find_element_by_text('精品推荐'):   #手机
            print("进入商城界面成功")
            self.driver.write_result("进入商城界面", "成功")
            self.driver.find_element_by_id("com.sofmit.gzsk:id/iv_back").click()
        else:
            print("进入商城界面失败")
            self.driver.write_result("进入商城界面", "失败")
            self.driver.stop()
            self.driver.start_app('com.sofmit.gzsk', '.mvp.ui.splash.SplashActivity')

    #测试景点按钮
    def test_scenic(self):
        self.driver.find_element_by_text('首页').click()
        self.driver.find_element_by_text('景点').click()
        if self.driver.find_element_by_text('推荐景点'):
            self.driver.find_element_by_text('主题类型').click()
            if self.driver.find_element_by_text('自然景观'):
                print("进入景点的修改主题类型测试成功")
                self.driver.write_result("进入修改景点的主题类型界面", "成功")
                self.driver.find_element_by_id("com.sofmit.gzsk:id/back").click()
            else:
                print("进入景点的修改主题类型测试失败")
                self.driver.write_result("进入修改景点的主题类型界面", "失败")
                self.driver.find_element_by_id("com.sofmit.gzsk:id/toolbar_back").click()
                self.driver.stop()
                self.driver.start_app('com.sofmit.gzsk', '.mvp.ui.splash.SplashActivity')
        else:
            print("进入景点界面失败")
            self.driver.write_result("进入商城界面", "失败")
            self.driver.stop()
            self.driver.start_app('com.sofmit.gzsk', '.mvp.ui.splash.SplashActivity')

    def test_quit(self):
        self.driver.find_element_by_text('我的').click()
        self.driver.find_element_by_text('设置').click()
        self.driver.find_element_by_text("退出登录").click()
        self.driver.find_element_by_id("com.sofmit.gzsk:id/toolbar_back").click()
        # self.driver.find_element_by_xpath('//*[@resource-id="com.sofmit.gzsk:id/editText1"]').send_keys(17706852578)
        # self.driver.find_element_by_xpath('//*[@resource-id="com.sofmit.gzsk:id/editText2"]').send_keys(83190042)
        if self.driver.find_element_by_text('未登录'):
            print("测试注销成功")
            self.driver.write_result("注销测试", "成功")
        else:
            print("测试注销失败")
            self.driver.write_result("注销测试", "失败")
            self.driver.stop()
            self.driver.start_app('com.sofmit.gzsk', '.mvp.ui.splash.SplashActivity')



if __name__ == '__main__':

    at=AndroidTest()
    au=AndroidUI()
    au.start_app('com.sofmit.gzsk', '.mvp.ui.splash.SplashActivity')
    at.test_login()
    at.test_store()
    at.test_scenic()
    at.test_service_alarm()
    at.test_quit()
    au.stop()